home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.1.5 / components / nsDownloadManagerUI.js < prev    next >
Text File  |  2009-11-08  |  6KB  |  160 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  * 
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is mozilla.org code.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Shawn Wilsher <me@shawnwilsher.com>.
  18.  * Portions created by the Initial Developer are Copyright (C) 2007
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  25.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  * 
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
  38.  
  39. ////////////////////////////////////////////////////////////////////////////////
  40. //// Constants
  41.  
  42. const Cc = Components.classes;
  43. const Ci = Components.interfaces;
  44. const Cr = Components.results;
  45. const DOWNLOAD_MANAGER_URL = "chrome://mozapps/content/downloads/downloads.xul";
  46. const PREF_FLASH_COUNT = "browser.download.manager.flashCount";
  47.  
  48. ////////////////////////////////////////////////////////////////////////////////
  49. //// nsDownloadManagerUI class
  50.  
  51. function nsDownloadManagerUI() {}
  52.  
  53. nsDownloadManagerUI.prototype = {
  54.   classDescription: "Used to show the Download Manager's UI to the user",
  55.   classID: Components.ID("7dfdf0d1-aff6-4a34-bad1-d0fe74601642"),
  56.   contractID: "@mozilla.org/download-manager-ui;1",
  57.  
  58.   //////////////////////////////////////////////////////////////////////////////
  59.   //// nsIDownloadManagerUI
  60.  
  61.   show: function show(aWindowContext, aID, aReason)
  62.   {
  63.     if (!aReason)
  64.       aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED;
  65.  
  66.     // First we see if it is already visible
  67.     let window = this.recentWindow;
  68.     if (window) {
  69.       window.focus();
  70.       
  71.       // If we are being asked to show again, with a user interaction reason,
  72.       // set the appropriate variable.
  73.       if (aReason == Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED)
  74.         window.gUserInteracted = true;
  75.       return;
  76.     }
  77.  
  78.     let parent = null;
  79.     // We try to get a window to use as the parent here.  If we don't have one,
  80.     // the download manager will close immediately after opening if the pref
  81.     // browser.download.manager.closeWhenDone is set to true.
  82.     try {
  83.       if (aWindowContext)
  84.         parent = aWindowContext.getInterface(Ci.nsIDOMWindow);
  85.     } catch (e) { /* it's OK to not have a parent window */ }
  86.  
  87.     // We pass the download manager and the nsIDownload we want selected (if any)
  88.     var params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
  89.  
  90.     // Don't fail if our passed in ID is invalid
  91.     var download = null;
  92.     try {
  93.       let dm = Cc["@mozilla.org/download-manager;1"].
  94.                getService(Ci.nsIDownloadManager);
  95.       download = dm.getDownload(aID);
  96.     } catch (ex) {}
  97.     params.appendElement(download, false);
  98.  
  99.     // Pass in the reason as well
  100.     let reason = Cc["@mozilla.org/supports-PRInt16;1"].
  101.                  createInstance(Ci.nsISupportsPRInt16);
  102.     reason.data = aReason;
  103.     params.appendElement(reason, false);
  104.  
  105.     var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
  106.              getService(Ci.nsIWindowWatcher);
  107.     ww.openWindow(parent,
  108.                   DOWNLOAD_MANAGER_URL,
  109.                   "Download:Manager",
  110.                   "chrome,dialog=no,resizable",
  111.                   params);
  112.   },
  113.  
  114.   get visible() {
  115.     return (null != this.recentWindow);
  116.   },
  117.  
  118.   getAttention: function getAttention()
  119.   {
  120.     if (!this.visible)
  121.       throw Cr.NS_ERROR_UNEXPECTED;
  122.  
  123.     var prefs = Cc["@mozilla.org/preferences-service;1"].
  124.                 getService(Ci.nsIPrefBranch);
  125.     // This preference may not be set, so defaulting to two.
  126.     let flashCount = 2;
  127.     try {
  128.       flashCount = prefs.getIntPref(PREF_FLASH_COUNT);
  129.     } catch (e) { }
  130.  
  131.     var win = this.recentWindow.QueryInterface(Ci.nsIDOMChromeWindow);
  132.     win.getAttentionWithCycleCount(flashCount);
  133.   },
  134.  
  135.   //////////////////////////////////////////////////////////////////////////////
  136.   //// nsDownloadManagerUI
  137.  
  138.   get recentWindow() {
  139.     var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
  140.              getService(Ci.nsIWindowMediator);
  141.     return wm.getMostRecentWindow("Download:Manager");
  142.   },
  143.  
  144.   //////////////////////////////////////////////////////////////////////////////
  145.   //// nsISupports
  146.  
  147.   QueryInterface: XPCOMUtils.generateQI([Ci.nsIDownloadManagerUI])
  148. };
  149.  
  150. ////////////////////////////////////////////////////////////////////////////////
  151. //// Module
  152.  
  153. let components = [nsDownloadManagerUI];
  154.  
  155. function NSGetModule(compMgr, fileSpec)
  156. {
  157.   return XPCOMUtils.generateModule(components);
  158. }
  159.  
  160.